<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_osmBuildingsLeaflet"></title>
    <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="osmbuildings" src="../../dist/leaflet/include-leaflet.js"></script>
<script>
    var map = new L.Map('map', {
        center: [39.916, 116.450],
        zoom: 16
    });
    var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
    var url = host + "/iserver/services/map-china400/rest/maps/China";
    L.supermap.tiledMapLayer(url).addTo(map);

    loadData();

    function loadData() {
        var data;
        $.get('../data/buildings.json', function (geojson) {
            data = geojson;
            new OSMBuildings(map)
                .date(new Date(2017, 5, 15, 17, 30))
                .set(geojson)
                .click(bindPopup);
        });


        function bindPopup(evt) {
            var name = getFeatureNameById(evt.feature);
            name = name || "<span style='color:red'>" + resources.text_noData + "</span>";
            L.popup().setContent(name).setLatLng(L.latLng(evt.lat, evt.lon)).openOn(map);
        }

        function getFeatureNameById(id) {
            if (!data || !id) {
                return null;
            }
            var features = data.features;
            for (var i = 0; i < features.length; i++) {
                if (features[i].properties.id === id) {
                    return features[i].properties.name;
                }
            }
        }
    }
</script>
</body>
</html>